package com.test.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.test.entity.*;
import com.test.service.StuOperatService;
import com.test.service.UserSercice;
import com.test.utils.ResultMsg;
import com.test.utils.TokenUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.swing.JOptionPane;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;
import sun.text.CompactByteArray;


import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserSercice userSercice;

    @Autowired
    private StuOperatService stuOperatService;

    @Autowired
    private TokenUtil tokenUtil;

//    @RequestMapping("/login_to")
//    @ResponseBody
//    public String loginTo(String u_acount, String u_password,String u_checkcode, HttpSession session) {
//
//        Jedis jedis = new Jedis("localhost");
//        String checkCode = session.getAttribute("checkCode").toString();
//        if(checkCode!=null&&u_checkcode!=null){
//            u_checkcode = u_checkcode.toUpperCase();
//            if (!u_checkcode.equals(checkCode)){
//                return "验证码错误";
//            }
//        }
//        Users users= userSercice.userLogin(u_acount, u_password);
//        if(users!=null&&!"".equals(users)){
//            String u_stutas  = users.getU_status();
//            if(!u_stutas.equals("1")){
//                return "账号禁用";
//            }
//        }
//        String result= null;
//        String identity = "1";
//        try{
//            result= users.getU_name();
//            identity = users.getU_Identity();
//        }catch (Exception e){
//
//        }
//        UsernamePasswordToken userLoginInfo = new UsernamePasswordToken (u_acount,u_password);
//        SecurityUtils.getSubject().login(userLoginInfo);
//
//        //将用户信息存入redis中
//        JSONObject jsonObject=new JSONObject();
//        String token = tokenUtil.getToken(users);
//        jsonObject.put("token", token);
//        jsonObject.put("user", users);
//        Object obj = JSONArray.toJSON(users);
//        String json = obj.toString();
//        jedis.set(token,json);
//        System.out.println("token:"+token);
//        if(result!=null&&!"".equals(result)){
//            if(identity.equals("1")){
//                jedis.set("stu_u_acount",u_acount);
//                session.setAttribute("stu_u_name",result);
//                session.setAttribute("stu_u_acount",u_acount);
//                session.setAttribute("u_password",u_password);
//                return result+"同学";
//            }else if (identity.equals("2")){
//                jedis.set("tea_u_acount",u_acount);
//                session.setAttribute("tea_u_acount",u_acount);
//                session.setAttribute("u_password",u_password);
//                session.setAttribute("tea_u_name",result);
//                return result+"老师";
//            }else if (identity.equals("3")){
//                jedis.set("mana_u_acount",u_acount);
//                session.setAttribute("mana_u_acount",u_acount);
//                session.setAttribute("u_password",u_password);
//                session.setAttribute("mana_u_name",result);
//                return result+"管理员";
//            }else if(identity.equals("4")){
//                jedis.set("comp_acount",u_acount);
//                session.setAttribute("comp_acount",u_acount);
//                session.setAttribute("u_password",u_password);
//                session.setAttribute("comp_u_name",result);
//                return result+"企业用户";
//            }else{
//                return "学生";
//            }
//
//        }else{
//            return "error";
//        }
//    }

    @RequestMapping("/login_to")
    @ResponseBody
    public ResultMsg loginTo(String u_acount, String u_password, String u_checkcode, HttpSession session) {
        ResultMsg resultMsg = new ResultMsg();
        Jedis jedis = new Jedis("localhost");
        String checkCode = session.getAttribute("checkCode").toString();
        if(checkCode!=null&&u_checkcode!=null){
            u_checkcode = u_checkcode.toUpperCase();
            if (!u_checkcode.equals(checkCode)){
                resultMsg.setResultCode("201");
                resultMsg.setResultMsg("验证码错误");
                resultMsg.setResultData("error");
            }
        }
        Users users= userSercice.userLogin(u_acount, u_password);
        if(users!=null&&!"".equals(users)){
            String u_stutas  = users.getU_status();
            if(!u_stutas.equals("1")){
                resultMsg.setResultCode("202");
                resultMsg.setResultMsg("账号禁用");
                resultMsg.setResultData("error");
            }
        }
        String result= null;
        String identity = "1";
        try{
            result= users.getU_name();
            identity = users.getU_Identity();
        }catch (Exception e){
            resultMsg.setResultCode("301");
            resultMsg.setResultMsg("用户不存在");
            resultMsg.setResultData("error");
        }
        UsernamePasswordToken userLoginInfo = new UsernamePasswordToken (u_acount,u_password);
        SecurityUtils.getSubject().login(userLoginInfo);

        //将用户信息存入redis中
        JSONObject jsonObject=new JSONObject();
        String token = tokenUtil.getToken(users);
        jsonObject.put("token", token);
        jsonObject.put("user", users);
        Object obj = JSONArray.toJSON(users);
        String json = obj.toString();
        jedis.set(token,json);
        System.out.println("token:"+token);
        if(result!=null&&!"".equals(result)){
            if(identity.equals("1")){
                jedis.set("stu_u_acount",u_acount);
                session.setAttribute("stu_u_name",result);
                session.setAttribute("stu_u_acount",u_acount);
                session.setAttribute("u_password",u_password);
                resultMsg.setResultCode("200");
                resultMsg.setResultMsg("请求成功");
                resultMsg.setResultData(result+"同学");
                resultMsg.setToken(token);
            }else if (identity.equals("2")){
                jedis.set("tea_u_acount",u_acount);
                session.setAttribute("tea_u_acount",u_acount);
                session.setAttribute("u_password",u_password);
                session.setAttribute("tea_u_name",result);
                resultMsg.setResultCode("200");
                resultMsg.setResultMsg("请求成功");
                resultMsg.setResultData(result+"老师");
                resultMsg.setToken(token);
            }else if (identity.equals("3")){
                jedis.set("mana_u_acount",u_acount);
                session.setAttribute("mana_u_acount",u_acount);
                session.setAttribute("u_password",u_password);
                session.setAttribute("mana_u_name",result);
                resultMsg.setResultCode("200");
                resultMsg.setResultMsg("请求成功");
                resultMsg.setResultData(result+"管理员");
                resultMsg.setToken(token);

            }else if(identity.equals("4")){
                jedis.set("comp_acount",u_acount);
                session.setAttribute("comp_acount",u_acount);
                session.setAttribute("u_password",u_password);
                session.setAttribute("comp_u_name",result);
                resultMsg.setResultCode("200");
                resultMsg.setResultMsg("请求成功");
                resultMsg.setResultData(result+"企业用户");
                resultMsg.setToken(token);
            }else{
                resultMsg.setResultCode("200");
                resultMsg.setResultMsg("请求成功");
                resultMsg.setResultData(result+"同学");
                resultMsg.setToken(token);
            }

        }else{
            resultMsg.setResultCode("301");
            resultMsg.setResultMsg("用户不存在");
            resultMsg.setResultData("error");
        }

        return resultMsg;

    }


    //vue版用户登录
    @RequestMapping("/login_to_vue")
    @ResponseBody
    public String loginToVue(String u_acount, String u_password, HttpSession session) {

        Users users= userSercice.userLogin(u_acount, u_password);
        if(users!=null&&!"".equals(users)){
            String u_stutas  = users.getU_status();
            if(!u_stutas.equals("1")){
                return "账号禁用";
            }
        }
        String result= null;
        String identity = "1";
        try{
            result= users.getU_name();
            identity = users.getU_Identity();
        }catch (Exception e){

        }

//        String name  = session.getAttribute("u_acount").toString();
        if(result!=null&&!"".equals(result)){
            if(identity.equals("1")){
                session.setAttribute("stu_u_name",result);
                session.setAttribute("stu_u_acount",u_acount);
                session.setAttribute("u_password",u_password);
                return result+"同学";
            }else if (identity.equals("2")){
                session.setAttribute("tea_u_acount",u_acount);
                session.setAttribute("u_password",u_password);
                session.setAttribute("tea_u_name",result);
                return result+"老师";
            }else if (identity.equals("3")){
                session.setAttribute("mana_u_acount",u_acount);
                session.setAttribute("u_password",u_password);
                session.setAttribute("mana_u_name",result);
                return result+"管理员";
            }else if(identity.equals("4")){
                session.setAttribute("comp_acount",u_acount);
                session.setAttribute("u_password",u_password);
                session.setAttribute("comp_u_name",result);
                return result+"企业用户";
            }else{
                return "学生";
            }

        }else{
            return "error";
        }
    }

    @RequestMapping("/no_login")
    @ResponseBody
    public String no_login(HttpSession session) {

         String u_acount =  session.getAttribute("stu_u_acount").toString();
         String u_password = null;
         if(u_acount!=null&&!"".equals(u_acount)){
             u_password = stuOperatService.getUpassword(u_acount);
         }
        Users users= userSercice.userLogin(u_acount, u_password);

        String result= null;
        String identity = "1";
        try{
            result= users.getU_name();
            identity = users.getU_Identity();
        }catch (Exception e){

        }

//        String name  = session.getAttribute("u_acount").toString();

        if(result!=null&&!"".equals(result)){
            session.setAttribute("stu_u_name",result);
            session.setAttribute("stu_u_acount",u_acount);
            session.setAttribute("u_password",u_password);
            return result+"同学";
        }else{
            return "error";
        }

    }


    @RequestMapping("/no_tealogin")
    @ResponseBody
    public String no_tealogin(HttpSession session) {

        String u_acount =  session.getAttribute("tea_u_acount").toString();
        String u_password = null;
        if(u_acount!=null&&!"".equals(u_acount)){
            u_password = stuOperatService.getUpassword(u_acount);
        }
        Users users= userSercice.userLogin(u_acount, u_password);

        String result= null;
        String identity = "1";
        try{
            result= users.getU_name();
            identity = users.getU_Identity();
        }catch (Exception e){

        }

//        String name  = session.getAttribute("u_acount").toString();

        if(result!=null&&!"".equals(result)){
            session.setAttribute("tea_u_acount",u_acount);
            session.setAttribute("u_password",u_password);
            session.setAttribute("tea_u_name",result);
            return result+"老师";
        }else{
            return "error";
        }

    }



    @RequestMapping("/no_complogin")
    @ResponseBody
    public String no_complogin(HttpSession session) {

        String u_acount =  session.getAttribute("comp_acount").toString();
        String u_password = null;
        if(u_acount!=null&&!"".equals(u_acount)){
            u_password = stuOperatService.getUpassword(u_acount);
        }
        Users users= userSercice.userLogin(u_acount, u_password);

        String result= null;
        String identity = "1";
        try{
            result= users.getU_name();
            identity = users.getU_Identity();
        }catch (Exception e){

        }

//        String name  = session.getAttribute("u_acount").toString();

        if(result!=null&&!"".equals(result)){
            session.setAttribute("comp_acount",u_acount);
            session.setAttribute("u_password",u_password);
            session.setAttribute("comp_u_name",result);
            return result+"企业用户";
        }else{
            return "error";
        }

    }


    @RequestMapping("/login_qrcode")
    @ResponseBody
    public String loginqrcode(Object object) {

        System.out.println(object);
        return null;

    }




    @RequestMapping("/login_app_to")
    @ResponseBody
    public String login_app_to(String u_acount, String u_password,String u_checkcode, HttpSession session) {

        Users users= userSercice.userLogin(u_acount, u_password);
        if(users!=null&&!"".equals(users)){
            String u_stutas  = users.getU_status();
            if(!u_stutas.equals("1")){
                return "账号禁用";
            }
        }
        String result= null;
        String identity = "1";
        try{
            result= users.getU_name();
            identity = users.getU_Identity();
        }catch (Exception e){

        }

//        String name  = session.getAttribute("u_acount").toString();
        if(result!=null&&!"".equals(result)){
            if(identity.equals("1")){
                session.setAttribute("stu_u_name",result);
                session.setAttribute("stu_u_acount",u_acount);
                session.setAttribute("u_password",u_password);
                return result+"同学";
            }else if (identity.equals("2")){
                session.setAttribute("tea_u_acount",u_acount);
                session.setAttribute("u_password",u_password);
                session.setAttribute("tea_u_name",result);
                return result+"老师";
            }else if (identity.equals("3")){
                session.setAttribute("mana_u_acount",u_acount);
                session.setAttribute("u_password",u_password);
                session.setAttribute("mana_u_name",result);
                return result+"管理员";
            }else if(identity.equals("4")){
                session.setAttribute("comp_acount",u_acount);
                session.setAttribute("u_password",u_password);
                session.setAttribute("comp_u_name",result);
                return result+"企业用户";
            }else{
                return "学生";
            }

        }else{
            return "error";
        }
    }


//对vue提供管理员登录接口
    @RequestMapping("/managerLogin")
    @ResponseBody
    public String managerLogin(String u_acount, String u_password, HttpSession session) {
        Users users= userSercice.managerLogin(u_acount, u_password);
        String result= null;
        String identity = "1";
        try{
            result= users.getU_name();
            identity = users.getU_Identity();
        }catch (Exception e){

        }
        session.setAttribute("mana_u_acount",u_acount);
        session.setAttribute("u_password",u_acount);
        if(result!=null&&!"".equals(result)){
            if (identity.equals("3")){
                session.setAttribute("mana_u_name",result);
                return result+"管理员";
            }else{
                return "error";
            }

        }else{
            return "error";
        }
    }


    @RequestMapping("/check_user")
    @ResponseBody
    public String checkUser(String u_acount, String u_password, HttpSession session) {
        try{
            String result= userSercice.checkUser(u_acount);
            if(result!=null&&!"".equals(result)){
                return result;
            }else{
                return "error";
            }
        }catch (Exception e){
            return "success";
        }
    }

    @RequestMapping("/insertuser")
    @ResponseBody
    public String insertuser(String u_name,String u_acount,String u_password,String u_Identity) {
        if(u_Identity.equals("学生注册")){
            u_Identity = "1";
        }else  if(u_Identity.equals("教师注册")){
            u_Identity = "2";
        }else if(u_Identity.equals("企业注册")){
            u_Identity = "4";
        }
        String result= userSercice.checkUser(u_acount);
        if(result!=null&&!"".equals(result)){
            return "重复添加";
        }else{
            userSercice.insertuser(u_name,u_acount, u_password,u_Identity);
            return "添加成功";
        }
    }

    @RequestMapping("/manaCreateUser")
    @ResponseBody
    public String manaCreateUser(String u_name,String u_acount,String u_Identity) {
        String result= userSercice.checkUser(u_acount);
        if(result!=null&&!"".equals(result)){
            return "重复添加";
        }else{
            userSercice.manaCreateUser(u_name,u_acount,u_Identity);
            return "添加成功";
        }
    }


    @RequestMapping("/manaloginout")
    @ResponseBody
    public String manaloginout(HttpSession session) {
        session.removeAttribute("mana_u_acount");
        session.removeAttribute("comp_u_name");
        session.removeAttribute("mana_u_name");
        return "已退出";
    }

    @RequestMapping("/comploginout")
    @ResponseBody
    public String comploginout(HttpSession session) {
        session.removeAttribute("comp_acount");
        session.removeAttribute("comp_u_name");
        session.removeAttribute("u_password");
        return "已退出";
    }

    @RequestMapping("/tealoginout")
    @ResponseBody
    public String tealoginout(HttpSession session) {
        session.removeAttribute("tea_u_acount");
        session.removeAttribute("tea_u_name");
        session.removeAttribute("u_password");
        return "已退出";
    }

    @RequestMapping("/stuloginout")
    @ResponseBody
    public String stuloginout(HttpSession session, HttpServletRequest request) {
        session.removeAttribute("stu_u_acount");
        session.removeAttribute("stu_u_name");
        session.removeAttribute("u_password");
        StuOperatService.stuAcount = null;
        SecurityUtils.getSubject().logout();
        String token = request.getHeader("token");
        TokenUtil.removeRedisUserInfo(token);
        return "已退出";
    }

    @RequestMapping("/studeleteAcount")
    @ResponseBody
    public String studeleteAcount(HttpSession session) {
        String acount = null;
            acount= session.getAttribute("stu_u_acount").toString();
        int result  = userSercice.deleteAcount(acount);
        if(result>0){
            return "已注销";
        }else{
            return "已放弃";
        }
    }


    @RequestMapping("/teadeleteAcount")
    @ResponseBody
    public String teadeleteAcount(HttpSession session) {
        String acount = null;
        acount= session.getAttribute("tea_u_acount").toString();
        int result  = userSercice.deleteAcount(acount);
        if(result>0){
            return "已注销";
        }else{
            return "已放弃";
        }
    }


    @RequestMapping("/compdeleteAcount")
    @ResponseBody
    public String compdeleteAcount(HttpSession session) {
        String acount = null;
        acount= session.getAttribute("comp_acount").toString();
        int result  = userSercice.deleteAcount(acount);
        if(result>0){
            return "已注销";
        }else{
            return "已放弃";
        }
    }


    @RequestMapping("/manadeleteAcount")
    @ResponseBody
    public String manadeleteAcount(HttpSession session) {
        String acount = null;
        acount= session.getAttribute("mana_u_acount").toString();
        int result  = userSercice.deleteAcount(acount);
        if(result>0){
            return "已注销";
        }else{
            return "已放弃";
        }
    }

    @RequestMapping("/stucheckpwd")
    @ResponseBody
    public String checkpwd(String u_oldpwd,HttpSession session){
        String acount = null;
        acount= session.getAttribute("stu_u_acount").toString();
             String  result  = userSercice.checkPwd(acount);
             if(result.equals(u_oldpwd)){
                 return "密码存在";
             }else{
                 return "原密码不正确";
             }
    }

    @RequestMapping("/teacheckpwd")
    @ResponseBody
    public String teacheckpwd(String u_oldpwd,HttpSession session){
        String acount = null;
        acount= session.getAttribute("tea_u_acount").toString();
        String  result  = userSercice.checkPwd(acount);
        if(result.equals(u_oldpwd)){
            return "密码存在";
        }else{
            return "原密码不正确";
        }
    }

    @RequestMapping("/compcheckpwd")
    @ResponseBody
    public String compcheckpwd(String u_oldpwd,HttpSession session){
        String acount = null;
        acount= session.getAttribute("comp_acount").toString();
        String  result  = userSercice.checkPwd(acount);
        if(result.equals(u_oldpwd)){
            return "密码存在";
        }else{
            return "原密码不正确";
        }
    }

    @RequestMapping("/manacheckpwd")
    @ResponseBody
    public String manacheckpwd(String u_oldpwd,HttpSession session){
        String acount = null;
        acount= session.getAttribute("mana_u_acount").toString();
        String  result  = userSercice.checkPwd(acount);
        if(result.equals(u_oldpwd)){
            return "密码存在";
        }else{
            return "原密码不正确";
        }
    }


    @RequestMapping("/stuupdatepwd")
    @ResponseBody
    public String stuupdatepwd(String u_newpwd,HttpSession session){
        String acount = null;
        acount= session.getAttribute("stu_u_acount").toString();
        int result  = userSercice.updatepwd(acount,u_newpwd);
        if(result>0){
            return "已修改";
        }else{
            return "修改失败";
        }
    }
    @RequestMapping("/teaupdatepwd")
    @ResponseBody
    public String teaupdatepwd(String u_newpwd,HttpSession session){
        String acount = null;
        acount= session.getAttribute("tea_u_acount").toString();
        int result  = userSercice.updatepwd(acount,u_newpwd);
        if(result>0){
            return "已修改";
        }else{
            return "修改失败";
        }
    }


    @RequestMapping("/compupdatepwd")
    @ResponseBody
    public String compupdatepwd(String u_newpwd,HttpSession session){
        String acount = null;
        acount= session.getAttribute("comp_acount").toString();
        int result  = userSercice.updatepwd(acount,u_newpwd);
        if(result>0){
            return "已修改";
        }else{
            return "修改失败";
        }
    }


    @RequestMapping("/manaupdatepwd")
    @ResponseBody
    public String manaupdatepwd(String u_newpwd,HttpSession session){
        String acount = null;
        acount= session.getAttribute("mana_u_acount").toString();
        int result  = userSercice.updatepwd(acount,u_newpwd);
        if(result>0){
            return "已修改";
        }else{
            return "修改失败";
        }
    }


    @RequestMapping("/submitStuBaseInfo")
    @ResponseBody
    public String submitStuBaseInfo(HttpSession session,StuAllInfoDto stuAllInfoDto){
        if(stuAllInfoDto.getStu_city()!=null&&!",".equals(stuAllInfoDto.getStu_city())){
            String[] Stu_city = stuAllInfoDto.getStu_city().split(",");
            stuAllInfoDto.setStu_city(Stu_city[0]);
        }
        if(stuAllInfoDto.getStu_county()!=null&&!",".equals(stuAllInfoDto.getStu_county())){
            String[] Stu_county = stuAllInfoDto.getStu_county().split(",");
            stuAllInfoDto.setStu_county(Stu_county[0]);
        }
        if(stuAllInfoDto.getStu_fromcity()!=null&&!",".equals(stuAllInfoDto.getStu_fromcity())){
            String[] Stu_fromcity = stuAllInfoDto.getStu_fromcity().split(",");
            stuAllInfoDto.setStu_fromcity(Stu_fromcity[0]);
        }

        String acount  = session.getAttribute("stu_u_acount").toString();
        stuAllInfoDto.setU_acount(acount);
        userSercice.deleteStuBaseInfo(acount);
        int result  = userSercice.insertStuBaseInfo(stuAllInfoDto);
        if(result>0){
            return "已保存";
        }else{
            return "未保存";
        }
    }
    @RequestMapping("/selectStuBaseInfo")
    @ResponseBody
    public StuAllInfoDto selectStuBaseInfo(HttpSession session){
        String acount  = session.getAttribute("stu_u_acount").toString();
        StuAllInfoDto stuAllInfoDto  = userSercice.selectStuBaseInfo(acount);
        if(stuAllInfoDto!=null){
            return stuAllInfoDto;
        }else{
            return null;
        }
    }


    @RequestMapping("/submitStuStatusInfo")
    @ResponseBody
    public String submitStuStatusInfo(HttpSession session,StuAllInfoDto stuAllInfoDto){
        if(stuAllInfoDto.getStu_profession()!=null&&!",".equals(stuAllInfoDto.getStu_profession())){
            String []  profession= stuAllInfoDto.getStu_profession().split(",");
            stuAllInfoDto.setStu_profession(profession[0]);
        }
        if(stuAllInfoDto.getStu_inTime()!=null&&!",".equals(stuAllInfoDto.getStu_inTime())){
            String []  intime= stuAllInfoDto.getStu_inTime().split(",");
            stuAllInfoDto.setStu_inTime(intime[0]);
        }
        if(stuAllInfoDto.getStu_outTime()!=null&&!",".equals(stuAllInfoDto.getStu_outTime())){
            String []  outtime= stuAllInfoDto.getStu_outTime().split(",");
            stuAllInfoDto.setStu_outTime(outtime[0]);
        }
        String acount  = session.getAttribute("stu_u_acount").toString();
        stuAllInfoDto.setU_acount(acount);
        userSercice.deleteStuStatusInfo(acount);
        int result  = userSercice.insertStuStatusInfo(stuAllInfoDto);
        if(result>0){
            return "已保存";
        }else{
            return "未保存";
        }
    }
    @RequestMapping("/selectStuStatusInfo")
    @ResponseBody
    public StuAllInfoDto selectStuStatusInfo(HttpSession session){
        String acount  = session.getAttribute("stu_u_acount").toString();
        StuAllInfoDto stuAllInfoDto  = userSercice.selectStuStatusInfo(acount);
        if(stuAllInfoDto!=null){
            return stuAllInfoDto;
        }else{
            return null;
        }
    }


    @RequestMapping("/submitStuJobInfo")
    @ResponseBody
    public String submitStuJobInfo(HttpSession session,StuAllInfoDto stuAllInfoDto){
        if(stuAllInfoDto.getStu_compcity()!=null&&!",".equals(stuAllInfoDto.getStu_compcity())){
            String[] Stu_city = stuAllInfoDto.getStu_compcity().split(",");
            stuAllInfoDto.setStu_compcity(Stu_city[0]);
        }
        if(stuAllInfoDto.getStu_compcounty()!=null&&!",".equals(stuAllInfoDto.getStu_compcounty())){
            String[] Stu_county = stuAllInfoDto.getStu_compcounty().split(",");
            stuAllInfoDto.setStu_compcounty(Stu_county[0]);
        }
        String acount  = session.getAttribute("stu_u_acount").toString();
        stuAllInfoDto.setU_acount(acount);
        userSercice.deleteStuJobInfo(acount);
        int result  = userSercice.insertStuJobInfo(stuAllInfoDto);
        if(result>0){
            return "已保存";
        }else{
            return "未保存";
        }
    }

    @RequestMapping("/selectStuJobInfo")
    @ResponseBody
    public StuAllInfoDto selectStuJobInfo(HttpSession session){
        String acount  = session.getAttribute("stu_u_acount").toString();
        StuAllInfoDto stuAllInfoDto  = userSercice.selectStuJobInfo(acount);
        if(stuAllInfoDto!=null){
            return stuAllInfoDto;
        }else{
            return null;
        }
    }


    @RequestMapping("/submitTeaBaseInfo")
    @ResponseBody
    public String submitTeaBaseInfo(HttpSession session, TeaAllInfoDto teaAllInfoDto){
        String acount  = session.getAttribute("tea_u_acount").toString();
        teaAllInfoDto.setU_acount(acount);
        userSercice.deleteTeaBaseInfo(acount);
        int result  = userSercice.insertTeaBaseInfo(teaAllInfoDto);
        if(result>0){
            return "已保存";
        }else{
            return "未保存";
        }
    }

    @RequestMapping("/selectTeaBaseInfo")
    @ResponseBody
    public TeaAllInfoDto selectTeaBaseInfo(HttpSession session){
        String acount  = session.getAttribute("tea_u_acount").toString();
        TeaAllInfoDto teaAllInfoDto  = userSercice.selectTeaBaseInfo(acount);
        if(teaAllInfoDto!=null){
            return teaAllInfoDto;
        }else{
            return null;
        }
    }

    @RequestMapping("/submitCompBaseInfo")
    @ResponseBody
    public String submitCompBaseInfo(HttpSession session, CompAllInfoDto compAllInfoDto){
        if(compAllInfoDto.getComp_city()!=null&&!",".equals(compAllInfoDto.getComp_city())){
            String[] Stu_city = compAllInfoDto.getComp_city().split(",");
            compAllInfoDto.setComp_city(Stu_city[0]);
        }
        if(compAllInfoDto.getComp_county()!=null&&!",".equals(compAllInfoDto.getComp_county())){
            String[] Stu_county = compAllInfoDto.getComp_county().split(",");
            compAllInfoDto.setComp_county(Stu_county[0]);
        }

        String acount  = session.getAttribute("comp_acount").toString();
        compAllInfoDto.setU_acount(acount);
        userSercice.deleteCompBaseInfo(acount);
        int result  = userSercice.insertCompBaseInfo(compAllInfoDto);
        if(result>0){
            return "已保存";
        }else{
            return "未保存";
        }
    }

    @RequestMapping("/selectCompBaseInfo")
    @ResponseBody
    public CompAllInfoDto selectCompBaseInfo(HttpSession session){
        String acount  = session.getAttribute("comp_acount").toString();
        CompAllInfoDto compAllInfoDto  = userSercice.selectCompBaseInfo(acount);
        if(compAllInfoDto!=null){
            return compAllInfoDto;
        }else{
            return null;
        }
    }

    @RequestMapping("/selectAllTeacher")
    @ResponseBody
    public List<TeaAllInfoDto> selectAllTeacher(){
        List<TeaAllInfoDto> tealist = userSercice.selectAllTeacher();
        if (tealist.size() > 0) {
            return tealist;
        }else{
            return null;
        }
    }



    @RequestMapping("/submitCompRecruitInfo")
    @ResponseBody
    public String submitCompRecruitInfo(HttpSession session, CompAllInfoDto compAllInfoDto){
        String acount  = session.getAttribute("comp_acount").toString();
        compAllInfoDto.setU_acount(acount);
        userSercice.deleteCompRecruitInfo(acount);
        int result  = userSercice.insertCompRecruitInfo(compAllInfoDto);
        if(result>0){
            return "已保存";
        }else{
            return "未保存";
        }
    }


    @RequestMapping("/selectCompRecruitInfo")
    @ResponseBody
    public CompAllInfoDto selectCompRecruitInfo(HttpSession session){
        String acount  = session.getAttribute("comp_acount").toString();
        CompAllInfoDto compAllInfoDto  = userSercice.selectCompRecruitInfo(acount);
        if(compAllInfoDto!=null){
            return compAllInfoDto;
        }else{
            return null;
        }
    }



}
